package com.jml.生命周期003;


import java.lang.annotation.Annotation;
import java.util.function.Supplier;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.ScopeMetadata;
import org.springframework.lang.Nullable;

/**
 * @author:jml
 * @date: 2019/11/4 16:31
 * @description：
 */
public class AnnotationConfigApplicationContenr初始化代码注释 {
	/*
	<T> void doRegisterBean(Class<T> annotatedClass, @Nullable Supplier<T> instanceSupplier,
            @Nullable String name,
			@Nullable Class<? extends Annotation>[] qualifiers,
			BeanDefinitionCustomizer... definitionCustomizers) {
		//表示注解方式启动的配置类，
		AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
		//判断是否有Condition的条件方式(@Conditional)
		if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {return;}
		//设置回调
		abd.setInstanceSupplier(instanceSupplier);
		//判断类上有没有@Scope，默认是单例
		ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
		//设置Scope
		abd.setScope(scopeMetadata.getScopeName());
		//判断是否有beanName，如果没有就生成beanName，默认是类名的小写作为bean的ID
		String beanName = (name != null ? name: this.beanNameGenerator.generateBeanName(abd, this.registry));
		//看config类上有没有加@lazy,@dependsOn等注解，有就放入BeanDefinition中
		AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
		if (qualifiers != null) {
			for (Class<? extends Annotation> qualifier : qualifiers) {
				if (Primary.class == qualifier) {
					abd.setPrimary(true);
				} else if (Lazy.class == qualifier) {
					abd.setLazyInit(true);
				} else {
					abd.addQualifier(new AutowireCandidateQualifier(qualifier));
				}
			}
		}
		for (BeanDefinitionCustomizer customizer : definitionCustomizers) {
			customizer.customize(abd);
		}
		//BeanDefinitionHolder包装了AnnotatedGenericBeanDefinition
		BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
		definitionHolder = AnnotationConfigUtils
				.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
		//把AnnotatedGenericBeanDefinition放入DefaultListableBeanFactory中
		//简单说就是把BeanDefinition放入BeanFactory中
		BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
	}*/
}
